import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {NzMessageService, NzModalRef, NzModalService} from 'ng-zorro-antd';

@Injectable()
export class UtilService {
  loadImgUrl = 'https://upload.lessonplan.cn';
  readImgUrl = 'https://static.lessonplan.cn/';
  defaultImg = '/assets/img/image/datouxiang.png';//默认头像;
  temUrl = 'https://templateserver.lessonplan.cn';
  currentTeam = null;//进入比赛详情的团队
  constructor(
    private http: HttpClient,
    private modal: NzModalService,
    private message: NzMessageService
  ) {
  }

  comfirm(text: string, callback): void {
    let confirmModal: NzModalRef;
    confirmModal = this.modal.confirm({
      nzTitle: text,
      nzOnOk: () => {
        callback();
      }
    });
  }

  remind(type: string, text: string): void {
    this.message.create(type, text);
  }

  /*路由守卫*/
  isCanEnterApp(UserGuid): Promise<any> {
    return this.http.get(`${this.temUrl}/PurchaseRecord/IsCanEnterApp?UserGuid=${UserGuid}&FK_AppGuid=f6876a3e-ba9c-43b3-5781-d080f3173153`)
      .toPromise().then(res => {
        return res;
      });
  }

  getUserInfo(): Promise<any> {
    // return new Promise((resolve, reject) => {
    //   resolve({status: 1, userGuid: '0c3d6e88-9f3e-4b57-ef5e-d3e3fec7130c'});
    // });
    return this.http.get(`/api/userInfo`).toPromise().then(res => {
      return res;
    });
  }

  logout(): Promise<any> {
    return this.http.get(`/logout`).toPromise().then(res => {
      return res;
    })
  }
}
